package com.tjise.test;

import com.aliyun.vod.upload.impl.UploadVideoImpl;
import com.aliyun.vod.upload.req.UploadVideoRequest;
import com.aliyun.vod.upload.resp.UploadVideoResponse;

/**
 * @program: tjise_shixun
 * @description: 本地上传
 * @author: 郑朝文
 * @create: 2021-06-25 17:48
 **/
public class UploadVideo {
    //            DefaultAcsClient defaultAcsClient = Test.initVodClient("LTAI5tEhgZLnTYiJcR14ue4k", "uKUoB4MuhHNMuFBO4D39qDWNRGqZfj");
    public static void main(String[] args) {
        testUploadVideo("LTAI5tEhgZLnTYiJcR14ue4k", "uKUoB4MuhHNMuFBO4D39qDWNRGqZfj", "测试上传", "E:\\temp\\2021-05-23 13-02-40.mp4");
    }


    /**
     * 本地文件上传接口
     *
     * @param accessKeyId
     * @param accessKeySecret
     * @param title
     * @param fileName
     */
    private static void testUploadVideo(String accessKeyId, String accessKeySecret, String title, String fileName) {
        UploadVideoRequest request = new UploadVideoRequest(accessKeyId, accessKeySecret, title, fileName);
        /* 可指定分片上传时每个分片的大小，默认为2M字节 */
        request.setPartSize(2 * 1024 * 1024L);
        /* 可指定分片上传时的并发线程数，默认为1，(注：该配置会占用服务器CPU资源，需根据服务器情况指定）*/
        request.setTaskNum(1);
        UploadVideoImpl uploader = new UploadVideoImpl();
        UploadVideoResponse response = uploader.uploadVideo(request);
        if (response.isSuccess()) {
            System.out.print("VideoId=" + response.getVideoId() + "\n");
        } else {
            /* 如果设置回调URL无效，不影响视频上传，可以返回VideoId同时会返回错误码。其他情况上传失败时，VideoId为空，此时需要根据返回错误码分析具体错误原因 */
            System.out.print("VideoId=" + response.getVideoId() + "\n");
            System.out.print("ErrorCode=" + response.getCode() + "\n");
            System.out.print("ErrorMessage=" + response.getMessage() + "\n");
        }
    }
}


